package com.hmily.dubbo.asm;

import com.hmily.dubbo.asm.core.GenerateClassBytesUtils;
import com.hmily.dubbo.asm.core.Handler;
import com.hmily.dubbo.asm.core.UserBean;

import java.util.ArrayList;
import java.util.List;

/**
 * <h1>Asm测试类。</h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2021-10-24
 */
public class AsmTest {

    public static void main(String[] args) throws Exception {
        System.out.println("hmily");
        List<UserBean> reqList = new ArrayList<>();

        reqList.add(new UserBean("G314"));
        reqList.add(new UserBean("hmily"));
        reqList.add(new UserBean("2157"));
        reqList.add(new UserBean("9527"));

        for (UserBean userBean : reqList) {
            // 默认从 mybatis 的拦截器里面拿到了准备更新 db 的数据对象
            Class returnClz = GenerateClassBytesUtils.toClass(
                    userBean.getClass(),
                    "Handler"
            );
            Object instance = returnClz.newInstance();
            Handler handler = (Handler) instance;

            // 这一步就是模拟加密操作
            handler.addBefore(userBean);
            System.out.println(userBean);

            // 假设执行 db

            // 再来 addAfter 解密操作
        }
    }
}